package com.example.pm.ending.server.controller;

import com.example.pm.ending.server.module.investor.AddNewInvestorModuleDTO;
import com.example.pm.ending.server.module.investor.InvestorModuleListVO;
import com.example.pm.ending.server.pojo.dto.InvestorUpdateDTO;
import com.example.pm.ending.server.pojo.vo.InvestorStandardVO;
import com.example.pm.ending.server.service.IInvestorModuleService;
import com.example.pm.ending.server.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/investors")
@Api(tags = "投资商管理模块")
public class InvestorModuleController {
    @Autowired
    IInvestorModuleService investorModuleService;
    //添加业务
    @PostMapping("/add-new")
    @ApiOperation("1.添加投资商")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void>addNewInvestor(@Valid AddNewInvestorModuleDTO addNewInvestorModuleDTO){
        log.debug("开始处理【添加投资商】的请求，参数：{}",addNewInvestorModuleDTO);
        investorModuleService.addNewInvestor(addNewInvestorModuleDTO);
        return JsonResult.ok();
    }

    //删除业务
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("2.根据ID删除投资商")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "投资商ID",required = true,dataType = "long")
    })
    public JsonResult<String> deleteInvestor(@PathVariable @Range(min = 1,message = "请提交有效投资商ID值！")Long id){
        log.debug("开始处理【根据ID删除投资商】的请求，参数：{}", id);
        investorModuleService.deleteInvestor(id);
        return JsonResult.ok("删除投资商成功,并清空该投资商相关的公告信息！");
    }

    //修改业务
    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("3.根据ID修改投资商")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "投资商ID",required = true,dataType = "long")
    })
    public JsonResult<Void> updateInvestorInfoById(@PathVariable @Range(min = 1,message = "请提交有效的投资商ID值!")Long id,
                                                   @Valid InvestorUpdateDTO investorUpdateDTO){
        log.debug("开始处理【修改投资商详情】的请求，ID：{}", id);
        investorModuleService.updateInvestorInfoById(investorUpdateDTO);
        return JsonResult.ok();
    }

    //ID查询业务
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("4.根据ID查询投资商详情")
    @ApiOperationSupport(order = 410)
    public JsonResult<InvestorStandardVO> getStandardById(
            @PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【根据ID查询投资商详情】的请求，参数：{}", id);
        InvestorStandardVO queryResult = investorModuleService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    //列表
    @GetMapping("/list")
    @ApiOperation("5.查询投资商列表")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<InvestorModuleListVO>> list() {
        log.debug("开始处理【查询投资商列表】的请求，无参数");
        List<InvestorModuleListVO> list = investorModuleService.getInvestorList();
        return JsonResult.ok(list);
    }

    @ApiOperation("6.投资商启动")
    @PostMapping("/{id}/enable")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "投资商ID", required = true, dataType = "long"),
    })
    public JsonResult<Void> setEnable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【修改投资商详情】的请求，ID：{}，新数据：{}", id);
        investorModuleService.investorEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("7.投资商禁用")
    @PostMapping("/{id}/disEnable")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "投资商ID", required = true, dataType = "long"),
    })
    public JsonResult<Void> setDisable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【修改投资商详情】的请求，ID：{}", id);
        investorModuleService.investorDisEnable(id);
        return JsonResult.ok();
    }
















}
